//
//  SymptomData.m
//
//  Created by lianchuang  on 14-12-5
//  Copyright (c) 2014 __MyCompanyName__. All rights reserved.
//

#import "SymptomData.h"


NSString *const kSymptomDataCid = @"cid";
NSString *const kSymptomDataIntroduction = @"introduction";
NSString *const kSymptomDataPicurl = @"picurl";
NSString *const kSymptomDataPic = @"pic";
NSString *const kSymptomDataCategory = @"category";
NSString *const kSymptomDataCount = @"count";


@interface SymptomData ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation SymptomData

@synthesize cid = _cid;
@synthesize introduction = _introduction;
@synthesize picurl = _picurl;
@synthesize pic = _pic;
@synthesize category = _category;
@synthesize count = _count;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if(self && [dict isKindOfClass:[NSDictionary class]]) {
            self.cid = [self objectOrNilForKey:kSymptomDataCid fromDictionary:dict];
            self.introduction = [self objectOrNilForKey:kSymptomDataIntroduction fromDictionary:dict];
            self.picurl = [self objectOrNilForKey:kSymptomDataPicurl fromDictionary:dict];
            self.pic = [self objectOrNilForKey:kSymptomDataPic fromDictionary:dict];
            self.category = [self objectOrNilForKey:kSymptomDataCategory fromDictionary:dict];
            self.count = [self objectOrNilForKey:kSymptomDataCount fromDictionary:dict];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:self.cid forKey:kSymptomDataCid];
    [mutableDict setValue:self.introduction forKey:kSymptomDataIntroduction];
    [mutableDict setValue:self.picurl forKey:kSymptomDataPicurl];
    [mutableDict setValue:self.pic forKey:kSymptomDataPic];
    [mutableDict setValue:self.category forKey:kSymptomDataCategory];
    [mutableDict setValue:self.count forKey:kSymptomDataCount];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description 
{
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];

    self.cid = [aDecoder decodeObjectForKey:kSymptomDataCid];
    self.introduction = [aDecoder decodeObjectForKey:kSymptomDataIntroduction];
    self.picurl = [aDecoder decodeObjectForKey:kSymptomDataPicurl];
    self.pic = [aDecoder decodeObjectForKey:kSymptomDataPic];
    self.category = [aDecoder decodeObjectForKey:kSymptomDataCategory];
    self.count = [aDecoder decodeObjectForKey:kSymptomDataCount];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeObject:_cid forKey:kSymptomDataCid];
    [aCoder encodeObject:_introduction forKey:kSymptomDataIntroduction];
    [aCoder encodeObject:_picurl forKey:kSymptomDataPicurl];
    [aCoder encodeObject:_pic forKey:kSymptomDataPic];
    [aCoder encodeObject:_category forKey:kSymptomDataCategory];
    [aCoder encodeObject:_count forKey:kSymptomDataCount];
}

- (id)copyWithZone:(NSZone *)zone
{
    SymptomData *copy = [[SymptomData alloc] init];
    
    if (copy) {

        copy.cid = [self.cid copyWithZone:zone];
        copy.introduction = [self.introduction copyWithZone:zone];
        copy.picurl = [self.picurl copyWithZone:zone];
        copy.pic = [self.pic copyWithZone:zone];
        copy.category = [self.category copyWithZone:zone];
        copy.count = [self.count copyWithZone:zone];
    }
    
    return copy;
}


@end
